<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - Lua 5.2.4 - src/lbaselib.c</title>
  <link rel="stylesheet" type="text/css" href="../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../index.html">top level</a> - <a href="index.html">src</a> - lbaselib.c</td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">Lua 5.2.4</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">235</td>
            <td class="headerCovTableEntry">240</td>
            <td class="headerCovTableEntryHi">97.9 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2019-06-13 19:44:16</td>
            <td></td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<span class="lineNum">       1 </span>            : /*
<span class="lineNum">       2 </span>            : ** $Id: lbaselib.c,v 1.276.1.1 2013/04/12 18:48:47 roberto Exp $
<span class="lineNum">       3 </span>            : ** Basic library
<span class="lineNum">       4 </span>            : ** See Copyright Notice in lua.h
<span class="lineNum">       5 </span>            : */
<span class="lineNum">       6 </span>            : 
<span class="lineNum">       7 </span>            : 
<span class="lineNum">       8 </span>            : 
<span class="lineNum">       9 </span>            : #include &lt;ctype.h&gt;
<span class="lineNum">      10 </span>            : #include &lt;stdio.h&gt;
<span class="lineNum">      11 </span>            : #include &lt;stdlib.h&gt;
<span class="lineNum">      12 </span>            : #include &lt;string.h&gt;
<span class="lineNum">      13 </span>            : 
<span class="lineNum">      14 </span>            : #define lbaselib_c
<span class="lineNum">      15 </span>            : #define LUA_LIB
<span class="lineNum">      16 </span>            : 
<span class="lineNum">      17 </span>            : #include &quot;lua.h&quot;
<span class="lineNum">      18 </span>            : 
<span class="lineNum">      19 </span>            : #include &quot;lauxlib.h&quot;
<span class="lineNum">      20 </span>            : #include &quot;lualib.h&quot;
<span class="lineNum">      21 </span>            : 
<span class="lineNum">      22 </span>            : 
<span class="lineNum">      23 </span><span class="lineCov">       1833 : static int luaB_print (lua_State *L) {</span>
<span class="lineNum">      24 </span><span class="lineCov">       1833 :   int n = lua_gettop(L);  /* number of arguments */</span>
<span class="lineNum">      25 </span>            :   int i;
<span class="lineNum">      26 </span><span class="lineCov">       1833 :   lua_getglobal(L, &quot;tostring&quot;);</span>
<span class="lineNum">      27 </span><span class="lineCov">       3669 :   for (i=1; i&lt;=n; i++) {</span>
<span class="lineNum">      28 </span>            :     const char *s;
<span class="lineNum">      29 </span>            :     size_t l;
<span class="lineNum">      30 </span><span class="lineCov">       1837 :     lua_pushvalue(L, -1);  /* function to be called */</span>
<span class="lineNum">      31 </span><span class="lineCov">       1837 :     lua_pushvalue(L, i);   /* value to print */</span>
<span class="lineNum">      32 </span><span class="lineCov">       1837 :     lua_call(L, 1, 1);</span>
<span class="lineNum">      33 </span><span class="lineCov">       1837 :     s = lua_tolstring(L, -1, &amp;l);  /* get result */</span>
<span class="lineNum">      34 </span><span class="lineCov">       1837 :     if (s == NULL)</span>
<span class="lineNum">      35 </span><span class="lineCov">          1 :       return luaL_error(L,</span>
<span class="lineNum">      36 </span>            :          LUA_QL(&quot;tostring&quot;) &quot; must return a string to &quot; LUA_QL(&quot;print&quot;));
<span class="lineNum">      37 </span><span class="lineCov">       1836 :     if (i&gt;1) luai_writestring(&quot;\t&quot;, 1);</span>
<span class="lineNum">      38 </span><span class="lineCov">       1836 :     luai_writestring(s, l);</span>
<span class="lineNum">      39 </span><span class="lineCov">       1836 :     lua_pop(L, 1);  /* pop result */</span>
<span class="lineNum">      40 </span>            :   }
<span class="lineNum">      41 </span><span class="lineCov">       1832 :   luai_writeline();</span>
<span class="lineNum">      42 </span><span class="lineCov">       1832 :   return 0;</span>
<span class="lineNum">      43 </span>            : }
<span class="lineNum">      44 </span>            : 
<span class="lineNum">      45 </span>            : 
<span class="lineNum">      46 </span>            : #define SPACECHARS      &quot; \f\n\r\t\v&quot;
<span class="lineNum">      47 </span>            : 
<span class="lineNum">      48 </span><span class="lineCov">        123 : static int luaB_tonumber (lua_State *L) {</span>
<span class="lineNum">      49 </span><span class="lineCov">        123 :   if (lua_isnoneornil(L, 2)) {  /* standard conversion */</span>
<span class="lineNum">      50 </span>            :     int isnum;
<span class="lineNum">      51 </span><span class="lineCov">        119 :     lua_Number n = lua_tonumberx(L, 1, &amp;isnum);</span>
<span class="lineNum">      52 </span><span class="lineCov">        119 :     if (isnum) {</span>
<span class="lineNum">      53 </span><span class="lineCov">        115 :       lua_pushnumber(L, n);</span>
<span class="lineNum">      54 </span><span class="lineCov">        115 :       return 1;</span>
<span class="lineNum">      55 </span>            :     }  /* else not a number; must be something */
<span class="lineNum">      56 </span><span class="lineCov">          4 :     luaL_checkany(L, 1);</span>
<span class="lineNum">      57 </span>            :   }
<span class="lineNum">      58 </span>            :   else {
<span class="lineNum">      59 </span>            :     size_t l;
<span class="lineNum">      60 </span><span class="lineCov">          4 :     const char *s = luaL_checklstring(L, 1, &amp;l);</span>
<span class="lineNum">      61 </span><span class="lineCov">          4 :     const char *e = s + l;  /* end point for 's' */</span>
<span class="lineNum">      62 </span><span class="lineCov">          4 :     int base = luaL_checkint(L, 2);</span>
<span class="lineNum">      63 </span><span class="lineCov">          4 :     int neg = 0;</span>
<span class="lineNum">      64 </span><span class="lineCov">          4 :     luaL_argcheck(L, 2 &lt;= base &amp;&amp; base &lt;= 36, 2, &quot;base out of range&quot;);</span>
<span class="lineNum">      65 </span><span class="lineCov">          3 :     s += strspn(s, SPACECHARS);  /* skip initial spaces */</span>
<span class="lineNum">      66 </span><span class="lineCov">          3 :     if (*s == '-') { s++; neg = 1; }  /* handle signal */</span>
<span class="lineNum">      67 </span><span class="lineCov">          3 :     else if (*s == '+') s++;</span>
<span class="lineNum">      68 </span><span class="lineCov">          3 :     if (isalnum((unsigned char)*s)) {</span>
<span class="lineNum">      69 </span><span class="lineCov">          3 :       lua_Number n = 0;</span>
<span class="lineNum">      70 </span>            :       do {
<span class="lineNum">      71 </span><span class="lineCov">         27 :         int digit = (isdigit((unsigned char)*s)) ? *s - '0'</span>
<span class="lineNum">      72 </span><span class="lineCov">          9 :                        : toupper((unsigned char)*s) - 'A' + 10;</span>
<span class="lineNum">      73 </span><span class="lineCov">          9 :         if (digit &gt;= base) break;  /* invalid numeral; force a fail */</span>
<span class="lineNum">      74 </span><span class="lineCov">          9 :         n = n * (lua_Number)base + (lua_Number)digit;</span>
<span class="lineNum">      75 </span><span class="lineCov">          9 :         s++;</span>
<span class="lineNum">      76 </span><span class="lineCov">          9 :       } while (isalnum((unsigned char)*s));</span>
<span class="lineNum">      77 </span><span class="lineCov">          3 :       s += strspn(s, SPACECHARS);  /* skip trailing spaces */</span>
<span class="lineNum">      78 </span><span class="lineCov">          3 :       if (s == e) {  /* no invalid trailing characters? */</span>
<span class="lineNum">      79 </span><span class="lineCov">          3 :         lua_pushnumber(L, (neg) ? -n : n);</span>
<span class="lineNum">      80 </span><span class="lineCov">          3 :         return 1;</span>
<span class="lineNum">      81 </span>            :       }  /* else not a number */
<span class="lineNum">      82 </span>            :     }  /* else not a number */
<span class="lineNum">      83 </span>            :   }
<span class="lineNum">      84 </span><span class="lineCov">          3 :   lua_pushnil(L);  /* not a number */</span>
<span class="lineNum">      85 </span><span class="lineCov">          3 :   return 1;</span>
<span class="lineNum">      86 </span>            : }
<span class="lineNum">      87 </span>            : 
<span class="lineNum">      88 </span>            : 
<span class="lineNum">      89 </span><span class="lineCov">         13 : static int luaB_error (lua_State *L) {</span>
<span class="lineNum">      90 </span><span class="lineCov">         13 :   int level = luaL_optint(L, 2, 1);</span>
<span class="lineNum">      91 </span><span class="lineCov">         13 :   lua_settop(L, 1);</span>
<span class="lineNum">      92 </span><span class="lineCov">         13 :   if (lua_isstring(L, 1) &amp;&amp; level &gt; 0) {  /* add extra information? */</span>
<span class="lineNum">      93 </span><span class="lineCov">          8 :     luaL_where(L, level);</span>
<span class="lineNum">      94 </span><span class="lineCov">          8 :     lua_pushvalue(L, 1);</span>
<span class="lineNum">      95 </span><span class="lineCov">          8 :     lua_concat(L, 2);</span>
<span class="lineNum">      96 </span>            :   }
<span class="lineNum">      97 </span><span class="lineCov">         13 :   return lua_error(L);</span>
<span class="lineNum">      98 </span>            : }
<span class="lineNum">      99 </span>            : 
<span class="lineNum">     100 </span>            : 
<span class="lineNum">     101 </span><span class="lineCov">         13 : static int luaB_getmetatable (lua_State *L) {</span>
<span class="lineNum">     102 </span><span class="lineCov">         13 :   luaL_checkany(L, 1);</span>
<span class="lineNum">     103 </span><span class="lineCov">         13 :   if (!lua_getmetatable(L, 1)) {</span>
<span class="lineNum">     104 </span><span class="lineCov">          5 :     lua_pushnil(L);</span>
<span class="lineNum">     105 </span><span class="lineCov">          5 :     return 1;  /* no metatable */</span>
<span class="lineNum">     106 </span>            :   }
<span class="lineNum">     107 </span><span class="lineCov">          8 :   luaL_getmetafield(L, 1, &quot;__metatable&quot;);</span>
<span class="lineNum">     108 </span><span class="lineCov">          8 :   return 1;  /* returns either __metatable field (if present) or metatable */</span>
<span class="lineNum">     109 </span>            : }
<span class="lineNum">     110 </span>            : 
<span class="lineNum">     111 </span>            : 
<span class="lineNum">     112 </span><span class="lineCov">         95 : static int luaB_setmetatable (lua_State *L) {</span>
<span class="lineNum">     113 </span><span class="lineCov">         95 :   int t = lua_type(L, 2);</span>
<span class="lineNum">     114 </span><span class="lineCov">         95 :   luaL_checktype(L, 1, LUA_TTABLE);</span>
<span class="lineNum">     115 </span><span class="lineCov">         95 :   luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,</span>
<span class="lineNum">     116 </span>            :                     &quot;nil or table expected&quot;);
<span class="lineNum">     117 </span><span class="lineCov">         94 :   if (luaL_getmetafield(L, 1, &quot;__metatable&quot;))</span>
<span class="lineNum">     118 </span><span class="lineCov">          1 :     return luaL_error(L, &quot;cannot change a protected metatable&quot;);</span>
<span class="lineNum">     119 </span><span class="lineCov">         93 :   lua_settop(L, 2);</span>
<span class="lineNum">     120 </span><span class="lineCov">         93 :   lua_setmetatable(L, 1);</span>
<span class="lineNum">     121 </span><span class="lineCov">         93 :   return 1;</span>
<span class="lineNum">     122 </span>            : }
<span class="lineNum">     123 </span>            : 
<span class="lineNum">     124 </span>            : 
<span class="lineNum">     125 </span><span class="lineCov">         17 : static int luaB_rawequal (lua_State *L) {</span>
<span class="lineNum">     126 </span><span class="lineCov">         17 :   luaL_checkany(L, 1);</span>
<span class="lineNum">     127 </span><span class="lineCov">         17 :   luaL_checkany(L, 2);</span>
<span class="lineNum">     128 </span><span class="lineCov">         17 :   lua_pushboolean(L, lua_rawequal(L, 1, 2));</span>
<span class="lineNum">     129 </span><span class="lineCov">         17 :   return 1;</span>
<span class="lineNum">     130 </span>            : }
<span class="lineNum">     131 </span>            : 
<span class="lineNum">     132 </span>            : 
<span class="lineNum">     133 </span><span class="lineCov">          3 : static int luaB_rawlen (lua_State *L) {</span>
<span class="lineNum">     134 </span><span class="lineCov">          3 :   int t = lua_type(L, 1);</span>
<span class="lineNum">     135 </span><span class="lineCov">          3 :   luaL_argcheck(L, t == LUA_TTABLE || t == LUA_TSTRING, 1,</span>
<span class="lineNum">     136 </span>            :                    &quot;table or string expected&quot;);
<span class="lineNum">     137 </span><span class="lineCov">          2 :   lua_pushinteger(L, lua_rawlen(L, 1));</span>
<span class="lineNum">     138 </span><span class="lineCov">          2 :   return 1;</span>
<span class="lineNum">     139 </span>            : }
<span class="lineNum">     140 </span>            : 
<span class="lineNum">     141 </span>            : 
<span class="lineNum">     142 </span><span class="lineCov">          5 : static int luaB_rawget (lua_State *L) {</span>
<span class="lineNum">     143 </span><span class="lineCov">          5 :   luaL_checktype(L, 1, LUA_TTABLE);</span>
<span class="lineNum">     144 </span><span class="lineCov">          5 :   luaL_checkany(L, 2);</span>
<span class="lineNum">     145 </span><span class="lineCov">          5 :   lua_settop(L, 2);</span>
<span class="lineNum">     146 </span><span class="lineCov">          5 :   lua_rawget(L, 1);</span>
<span class="lineNum">     147 </span><span class="lineCov">          5 :   return 1;</span>
<span class="lineNum">     148 </span>            : }
<span class="lineNum">     149 </span>            : 
<span class="lineNum">     150 </span><span class="lineCov">          3 : static int luaB_rawset (lua_State *L) {</span>
<span class="lineNum">     151 </span><span class="lineCov">          3 :   luaL_checktype(L, 1, LUA_TTABLE);</span>
<span class="lineNum">     152 </span><span class="lineCov">          3 :   luaL_checkany(L, 2);</span>
<span class="lineNum">     153 </span><span class="lineCov">          3 :   luaL_checkany(L, 3);</span>
<span class="lineNum">     154 </span><span class="lineCov">          3 :   lua_settop(L, 3);</span>
<span class="lineNum">     155 </span><span class="lineCov">          3 :   lua_rawset(L, 1);</span>
<span class="lineNum">     156 </span><span class="lineCov">          2 :   return 1;</span>
<span class="lineNum">     157 </span>            : }
<span class="lineNum">     158 </span>            : 
<span class="lineNum">     159 </span>            : 
<span class="lineNum">     160 </span><span class="lineCov">         16 : static int luaB_collectgarbage (lua_State *L) {</span>
<span class="lineNum">     161 </span>            :   static const char *const opts[] = {&quot;stop&quot;, &quot;restart&quot;, &quot;collect&quot;,
<span class="lineNum">     162 </span>            :     &quot;count&quot;, &quot;step&quot;, &quot;setpause&quot;, &quot;setstepmul&quot;,
<span class="lineNum">     163 </span>            :     &quot;setmajorinc&quot;, &quot;isrunning&quot;, &quot;generational&quot;, &quot;incremental&quot;, NULL};
<span class="lineNum">     164 </span>            :   static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,
<span class="lineNum">     165 </span>            :     LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL,
<span class="lineNum">     166 </span>            :     LUA_GCSETMAJORINC, LUA_GCISRUNNING, LUA_GCGEN, LUA_GCINC};
<span class="lineNum">     167 </span><span class="lineCov">         16 :   int o = optsnum[luaL_checkoption(L, 1, &quot;collect&quot;, opts)];</span>
<span class="lineNum">     168 </span><span class="lineCov">         15 :   int ex = luaL_optint(L, 2, 0);</span>
<span class="lineNum">     169 </span><span class="lineCov">         15 :   int res = lua_gc(L, o, ex);</span>
<span class="lineNum">     170 </span><span class="lineCov">         15 :   switch (o) {</span>
<span class="lineNum">     171 </span><span class="lineCov">          1 :     case LUA_GCCOUNT: {</span>
<span class="lineNum">     172 </span><span class="lineCov">          1 :       int b = lua_gc(L, LUA_GCCOUNTB, 0);</span>
<span class="lineNum">     173 </span><span class="lineCov">          1 :       lua_pushnumber(L, res + ((lua_Number)b/1024));</span>
<span class="lineNum">     174 </span><span class="lineCov">          1 :       lua_pushinteger(L, b);</span>
<span class="lineNum">     175 </span><span class="lineCov">          1 :       return 2;</span>
<span class="lineNum">     176 </span>            :     }
<span class="lineNum">     177 </span><span class="lineCov">          5 :     case LUA_GCSTEP: case LUA_GCISRUNNING: {</span>
<span class="lineNum">     178 </span><span class="lineCov">          5 :       lua_pushboolean(L, res);</span>
<span class="lineNum">     179 </span><span class="lineCov">          5 :       return 1;</span>
<span class="lineNum">     180 </span>            :     }
<span class="lineNum">     181 </span><span class="lineCov">          9 :     default: {</span>
<span class="lineNum">     182 </span><span class="lineCov">          9 :       lua_pushinteger(L, res);</span>
<span class="lineNum">     183 </span><span class="lineCov">          9 :       return 1;</span>
<span class="lineNum">     184 </span>            :     }
<span class="lineNum">     185 </span>            :   }
<span class="lineNum">     186 </span>            : }
<span class="lineNum">     187 </span>            : 
<span class="lineNum">     188 </span>            : 
<span class="lineNum">     189 </span><span class="lineCov">        130 : static int luaB_type (lua_State *L) {</span>
<span class="lineNum">     190 </span><span class="lineCov">        130 :   luaL_checkany(L, 1);</span>
<span class="lineNum">     191 </span><span class="lineCov">        129 :   lua_pushstring(L, luaL_typename(L, 1));</span>
<span class="lineNum">     192 </span><span class="lineCov">        129 :   return 1;</span>
<span class="lineNum">     193 </span>            : }
<span class="lineNum">     194 </span>            : 
<span class="lineNum">     195 </span>            : 
<span class="lineNum">     196 </span><span class="lineCov">       5934 : static int pairsmeta (lua_State *L, const char *method, int iszero,</span>
<span class="lineNum">     197 </span>            :                       lua_CFunction iter) {
<span class="lineNum">     198 </span><span class="lineCov">       5934 :   if (!luaL_getmetafield(L, 1, method)) {  /* no metamethod? */</span>
<span class="lineNum">     199 </span><span class="lineCov">       5932 :     luaL_checktype(L, 1, LUA_TTABLE);  /* argument must be a table */</span>
<span class="lineNum">     200 </span><span class="lineCov">       5932 :     lua_pushcfunction(L, iter);  /* will return generator, */</span>
<span class="lineNum">     201 </span><span class="lineCov">       5932 :     lua_pushvalue(L, 1);  /* state, */</span>
<span class="lineNum">     202 </span><span class="lineCov">       5932 :     if (iszero) lua_pushinteger(L, 0);  /* and initial value */</span>
<span class="lineNum">     203 </span><span class="lineCov">          6 :     else lua_pushnil(L);</span>
<span class="lineNum">     204 </span>            :   }
<span class="lineNum">     205 </span>            :   else {
<span class="lineNum">     206 </span><span class="lineCov">          2 :     lua_pushvalue(L, 1);  /* argument 'self' to metamethod */</span>
<span class="lineNum">     207 </span><span class="lineCov">          2 :     lua_call(L, 1, 3);  /* get 3 values from metamethod */</span>
<span class="lineNum">     208 </span>            :   }
<span class="lineNum">     209 </span><span class="lineCov">       5934 :   return 3;</span>
<span class="lineNum">     210 </span>            : }
<span class="lineNum">     211 </span>            : 
<span class="lineNum">     212 </span>            : 
<span class="lineNum">     213 </span><span class="lineCov">         45 : static int luaB_next (lua_State *L) {</span>
<span class="lineNum">     214 </span><span class="lineCov">         45 :   luaL_checktype(L, 1, LUA_TTABLE);</span>
<span class="lineNum">     215 </span><span class="lineCov">         44 :   lua_settop(L, 2);  /* create a 2nd argument if there isn't one */</span>
<span class="lineNum">     216 </span><span class="lineCov">         44 :   if (lua_next(L, 1))</span>
<span class="lineNum">     217 </span><span class="lineCov">         31 :     return 2;</span>
<span class="lineNum">     218 </span>            :   else {
<span class="lineNum">     219 </span><span class="lineCov">         12 :     lua_pushnil(L);</span>
<span class="lineNum">     220 </span><span class="lineCov">         12 :     return 1;</span>
<span class="lineNum">     221 </span>            :   }
<span class="lineNum">     222 </span>            : }
<span class="lineNum">     223 </span>            : 
<span class="lineNum">     224 </span>            : 
<span class="lineNum">     225 </span><span class="lineCov">          7 : static int luaB_pairs (lua_State *L) {</span>
<span class="lineNum">     226 </span><span class="lineCov">          7 :   return pairsmeta(L, &quot;__pairs&quot;, 0, luaB_next);</span>
<span class="lineNum">     227 </span>            : }
<span class="lineNum">     228 </span>            : 
<span class="lineNum">     229 </span>            : 
<span class="lineNum">     230 </span><span class="lineCov">      46287 : static int ipairsaux (lua_State *L) {</span>
<span class="lineNum">     231 </span><span class="lineCov">      46287 :   int i = luaL_checkint(L, 2);</span>
<span class="lineNum">     232 </span><span class="lineCov">      46287 :   luaL_checktype(L, 1, LUA_TTABLE);</span>
<span class="lineNum">     233 </span><span class="lineCov">      46287 :   i++;  /* next value */</span>
<span class="lineNum">     234 </span><span class="lineCov">      46287 :   lua_pushinteger(L, i);</span>
<span class="lineNum">     235 </span><span class="lineCov">      46287 :   lua_rawgeti(L, 1, i);</span>
<span class="lineNum">     236 </span><span class="lineCov">      46287 :   return (lua_isnil(L, -1)) ? 1 : 2;</span>
<span class="lineNum">     237 </span>            : }
<span class="lineNum">     238 </span>            : 
<span class="lineNum">     239 </span>            : 
<span class="lineNum">     240 </span><span class="lineCov">       5927 : static int luaB_ipairs (lua_State *L) {</span>
<span class="lineNum">     241 </span><span class="lineCov">       5927 :   return pairsmeta(L, &quot;__ipairs&quot;, 1, ipairsaux);</span>
<span class="lineNum">     242 </span>            : }
<span class="lineNum">     243 </span>            : 
<span class="lineNum">     244 </span>            : 
<span class="lineNum">     245 </span><span class="lineCov">        218 : static int load_aux (lua_State *L, int status, int envidx) {</span>
<span class="lineNum">     246 </span><span class="lineCov">        218 :   if (status == LUA_OK) {</span>
<span class="lineNum">     247 </span><span class="lineCov">        178 :     if (envidx != 0) {  /* 'env' parameter? */</span>
<span class="lineNum">     248 </span><span class="lineCov">          2 :       lua_pushvalue(L, envidx);  /* environment for loaded function */</span>
<span class="lineNum">     249 </span><span class="lineCov">          2 :       if (!lua_setupvalue(L, -2, 1))  /* set it as 1st upvalue */</span>
<span class="lineNum">     250 </span><span class="lineNoCov">          0 :         lua_pop(L, 1);  /* remove 'env' if not used by previous call */</span>
<span class="lineNum">     251 </span>            :     }
<span class="lineNum">     252 </span><span class="lineCov">        178 :     return 1;</span>
<span class="lineNum">     253 </span>            :   }
<span class="lineNum">     254 </span>            :   else {  /* error (message is on top of the stack) */
<span class="lineNum">     255 </span><span class="lineCov">         40 :     lua_pushnil(L);</span>
<span class="lineNum">     256 </span><span class="lineCov">         40 :     lua_insert(L, -2);  /* put before error message */</span>
<span class="lineNum">     257 </span><span class="lineCov">         40 :     return 2;  /* return nil plus error message */</span>
<span class="lineNum">     258 </span>            :   }
<span class="lineNum">     259 </span>            : }
<span class="lineNum">     260 </span>            : 
<span class="lineNum">     261 </span>            : 
<span class="lineNum">     262 </span><span class="lineCov">          6 : static int luaB_loadfile (lua_State *L) {</span>
<span class="lineNum">     263 </span><span class="lineCov">          6 :   const char *fname = luaL_optstring(L, 1, NULL);</span>
<span class="lineNum">     264 </span><span class="lineCov">          6 :   const char *mode = luaL_optstring(L, 2, NULL);</span>
<span class="lineNum">     265 </span><span class="lineCov">          6 :   int env = (!lua_isnone(L, 3) ? 3 : 0);  /* 'env' index or 0 if no 'env' */</span>
<span class="lineNum">     266 </span><span class="lineCov">          6 :   int status = luaL_loadfilex(L, fname, mode);</span>
<span class="lineNum">     267 </span><span class="lineCov">          6 :   return load_aux(L, status, env);</span>
<span class="lineNum">     268 </span>            : }
<span class="lineNum">     269 </span>            : 
<span class="lineNum">     270 </span>            : 
<span class="lineNum">     271 </span>            : /*
<span class="lineNum">     272 </span>            : ** {======================================================
<span class="lineNum">     273 </span>            : ** Generic Read function
<span class="lineNum">     274 </span>            : ** =======================================================
<span class="lineNum">     275 </span>            : */
<span class="lineNum">     276 </span>            : 
<span class="lineNum">     277 </span>            : 
<span class="lineNum">     278 </span>            : /*
<span class="lineNum">     279 </span>            : ** reserved slot, above all arguments, to hold a copy of the returned
<span class="lineNum">     280 </span>            : ** string to avoid it being collected while parsed. 'load' has four
<span class="lineNum">     281 </span>            : ** optional arguments (chunk, source name, mode, and environment).
<span class="lineNum">     282 </span>            : */
<span class="lineNum">     283 </span>            : #define RESERVEDSLOT    5
<span class="lineNum">     284 </span>            : 
<span class="lineNum">     285 </span>            : 
<span class="lineNum">     286 </span>            : /*
<span class="lineNum">     287 </span>            : ** Reader for generic `load' function: `lua_load' uses the
<span class="lineNum">     288 </span>            : ** stack for internal stuff, so the reader cannot change the
<span class="lineNum">     289 </span>            : ** stack top. Instead, it keeps its resulting string in a
<span class="lineNum">     290 </span>            : ** reserved slot inside the stack.
<span class="lineNum">     291 </span>            : */
<span class="lineNum">     292 </span><span class="lineCov">          6 : static const char *generic_reader (lua_State *L, void *ud, size_t *size) {</span>
<span class="lineNum">     293 </span>            :   (void)(ud);  /* not used */
<span class="lineNum">     294 </span><span class="lineCov">          6 :   luaL_checkstack(L, 2, &quot;too many nested functions&quot;);</span>
<span class="lineNum">     295 </span><span class="lineCov">          6 :   lua_pushvalue(L, 1);  /* get function */</span>
<span class="lineNum">     296 </span><span class="lineCov">          6 :   lua_call(L, 0, 1);  /* call it */</span>
<span class="lineNum">     297 </span><span class="lineCov">          6 :   if (lua_isnil(L, -1)) {</span>
<span class="lineNum">     298 </span><span class="lineCov">          3 :     lua_pop(L, 1);  /* pop result */</span>
<span class="lineNum">     299 </span><span class="lineCov">          3 :     *size = 0;</span>
<span class="lineNum">     300 </span><span class="lineCov">          3 :     return NULL;</span>
<span class="lineNum">     301 </span>            :   }
<span class="lineNum">     302 </span><span class="lineCov">          3 :   else if (!lua_isstring(L, -1))</span>
<span class="lineNum">     303 </span><span class="lineCov">          1 :     luaL_error(L, &quot;reader function must return a string&quot;);</span>
<span class="lineNum">     304 </span><span class="lineCov">          2 :   lua_replace(L, RESERVEDSLOT);  /* save string in reserved slot */</span>
<span class="lineNum">     305 </span><span class="lineCov">          2 :   return lua_tolstring(L, RESERVEDSLOT, size);</span>
<span class="lineNum">     306 </span>            : }
<span class="lineNum">     307 </span>            : 
<span class="lineNum">     308 </span>            : 
<span class="lineNum">     309 </span><span class="lineCov">        212 : static int luaB_load (lua_State *L) {</span>
<span class="lineNum">     310 </span>            :   int status;
<span class="lineNum">     311 </span>            :   size_t l;
<span class="lineNum">     312 </span><span class="lineCov">        212 :   const char *s = lua_tolstring(L, 1, &amp;l);</span>
<span class="lineNum">     313 </span><span class="lineCov">        212 :   const char *mode = luaL_optstring(L, 3, &quot;bt&quot;);</span>
<span class="lineNum">     314 </span><span class="lineCov">        212 :   int env = (!lua_isnone(L, 4) ? 4 : 0);  /* 'env' index or 0 if no 'env' */</span>
<span class="lineNum">     315 </span><span class="lineCov">        212 :   if (s != NULL) {  /* loading a string? */</span>
<span class="lineNum">     316 </span><span class="lineCov">        207 :     const char *chunkname = luaL_optstring(L, 2, s);</span>
<span class="lineNum">     317 </span><span class="lineCov">        207 :     status = luaL_loadbufferx(L, s, l, chunkname, mode);</span>
<span class="lineNum">     318 </span>            :   }
<span class="lineNum">     319 </span>            :   else {  /* loading from a reader function */
<span class="lineNum">     320 </span><span class="lineCov">          5 :     const char *chunkname = luaL_optstring(L, 2, &quot;=(load)&quot;);</span>
<span class="lineNum">     321 </span><span class="lineCov">          5 :     luaL_checktype(L, 1, LUA_TFUNCTION);</span>
<span class="lineNum">     322 </span><span class="lineCov">          5 :     lua_settop(L, RESERVEDSLOT);  /* create reserved slot */</span>
<span class="lineNum">     323 </span><span class="lineCov">          5 :     status = lua_load(L, generic_reader, NULL, chunkname, mode);</span>
<span class="lineNum">     324 </span>            :   }
<span class="lineNum">     325 </span><span class="lineCov">        212 :   return load_aux(L, status, env);</span>
<span class="lineNum">     326 </span>            : }
<span class="lineNum">     327 </span>            : 
<span class="lineNum">     328 </span>            : /* }====================================================== */
<span class="lineNum">     329 </span>            : 
<span class="lineNum">     330 </span>            : 
<span class="lineNum">     331 </span><span class="lineCov">          3 : static int dofilecont (lua_State *L) {</span>
<span class="lineNum">     332 </span><span class="lineCov">          3 :   return lua_gettop(L) - 1;</span>
<span class="lineNum">     333 </span>            : }
<span class="lineNum">     334 </span>            : 
<span class="lineNum">     335 </span>            : 
<span class="lineNum">     336 </span><span class="lineCov">          5 : static int luaB_dofile (lua_State *L) {</span>
<span class="lineNum">     337 </span><span class="lineCov">          5 :   const char *fname = luaL_optstring(L, 1, NULL);</span>
<span class="lineNum">     338 </span><span class="lineCov">          5 :   lua_settop(L, 1);</span>
<span class="lineNum">     339 </span><span class="lineCov">          5 :   if (luaL_loadfile(L, fname) != LUA_OK)</span>
<span class="lineNum">     340 </span><span class="lineCov">          2 :     return lua_error(L);</span>
<span class="lineNum">     341 </span><span class="lineCov">          3 :   lua_callk(L, 0, LUA_MULTRET, 0, dofilecont);</span>
<span class="lineNum">     342 </span><span class="lineCov">          3 :   return dofilecont(L);</span>
<span class="lineNum">     343 </span>            : }
<span class="lineNum">     344 </span>            : 
<span class="lineNum">     345 </span>            : 
<span class="lineNum">     346 </span><span class="lineCov">       5929 : static int luaB_assert (lua_State *L) {</span>
<span class="lineNum">     347 </span><span class="lineCov">       5929 :   if (!lua_toboolean(L, 1))</span>
<span class="lineNum">     348 </span><span class="lineCov">         10 :     return luaL_error(L, &quot;%s&quot;, luaL_optstring(L, 2, &quot;assertion failed!&quot;));</span>
<span class="lineNum">     349 </span><span class="lineCov">       5919 :   return lua_gettop(L);</span>
<span class="lineNum">     350 </span>            : }
<span class="lineNum">     351 </span>            : 
<span class="lineNum">     352 </span>            : 
<span class="lineNum">     353 </span><span class="lineCov">         12 : static int luaB_select (lua_State *L) {</span>
<span class="lineNum">     354 </span><span class="lineCov">         12 :   int n = lua_gettop(L);</span>
<span class="lineNum">     355 </span><span class="lineCov">         12 :   if (lua_type(L, 1) == LUA_TSTRING &amp;&amp; *lua_tostring(L, 1) == '#') {</span>
<span class="lineNum">     356 </span><span class="lineCov">          2 :     lua_pushinteger(L, n-1);</span>
<span class="lineNum">     357 </span><span class="lineCov">          2 :     return 1;</span>
<span class="lineNum">     358 </span>            :   }
<span class="lineNum">     359 </span>            :   else {
<span class="lineNum">     360 </span><span class="lineCov">         10 :     int i = luaL_checkint(L, 1);</span>
<span class="lineNum">     361 </span><span class="lineCov">         10 :     if (i &lt; 0) i = n + i;</span>
<span class="lineNum">     362 </span><span class="lineCov">          6 :     else if (i &gt; n) i = n;</span>
<span class="lineNum">     363 </span><span class="lineCov">         10 :     luaL_argcheck(L, 1 &lt;= i, 1, &quot;index out of range&quot;);</span>
<span class="lineNum">     364 </span><span class="lineCov">          8 :     return n - i;</span>
<span class="lineNum">     365 </span>            :   }
<span class="lineNum">     366 </span>            : }
<span class="lineNum">     367 </span>            : 
<span class="lineNum">     368 </span>            : 
<span class="lineNum">     369 </span><span class="lineCov">        514 : static int finishpcall (lua_State *L, int status) {</span>
<span class="lineNum">     370 </span><span class="lineCov">        514 :   if (!lua_checkstack(L, 1)) {  /* no space for extra boolean? */</span>
<span class="lineNum">     371 </span><span class="lineNoCov">          0 :     lua_settop(L, 0);  /* create space for return values */</span>
<span class="lineNum">     372 </span><span class="lineNoCov">          0 :     lua_pushboolean(L, 0);</span>
<span class="lineNum">     373 </span><span class="lineNoCov">          0 :     lua_pushstring(L, &quot;stack overflow&quot;);</span>
<span class="lineNum">     374 </span><span class="lineNoCov">          0 :     return 2;  /* return false, msg */</span>
<span class="lineNum">     375 </span>            :   }
<span class="lineNum">     376 </span><span class="lineCov">        514 :   lua_pushboolean(L, status);  /* first result (status) */</span>
<span class="lineNum">     377 </span><span class="lineCov">        514 :   lua_replace(L, 1);  /* put first result in first slot */</span>
<span class="lineNum">     378 </span><span class="lineCov">        514 :   return lua_gettop(L);</span>
<span class="lineNum">     379 </span>            : }
<span class="lineNum">     380 </span>            : 
<span class="lineNum">     381 </span>            : 
<span class="lineNum">     382 </span><span class="lineCov">          2 : static int pcallcont (lua_State *L) {</span>
<span class="lineNum">     383 </span><span class="lineCov">          2 :   int status = lua_getctx(L, NULL);</span>
<span class="lineNum">     384 </span><span class="lineCov">          2 :   return finishpcall(L, (status == LUA_YIELD));</span>
<span class="lineNum">     385 </span>            : }
<span class="lineNum">     386 </span>            : 
<span class="lineNum">     387 </span>            : 
<span class="lineNum">     388 </span><span class="lineCov">        506 : static int luaB_pcall (lua_State *L) {</span>
<span class="lineNum">     389 </span>            :   int status;
<span class="lineNum">     390 </span><span class="lineCov">        506 :   luaL_checkany(L, 1);</span>
<span class="lineNum">     391 </span><span class="lineCov">        506 :   lua_pushnil(L);</span>
<span class="lineNum">     392 </span><span class="lineCov">        506 :   lua_insert(L, 1);  /* create space for status result */</span>
<span class="lineNum">     393 </span><span class="lineCov">        506 :   status = lua_pcallk(L, lua_gettop(L) - 2, LUA_MULTRET, 0, 0, pcallcont);</span>
<span class="lineNum">     394 </span><span class="lineCov">        505 :   return finishpcall(L, (status == LUA_OK));</span>
<span class="lineNum">     395 </span>            : }
<span class="lineNum">     396 </span>            : 
<span class="lineNum">     397 </span>            : 
<span class="lineNum">     398 </span><span class="lineCov">          9 : static int luaB_xpcall (lua_State *L) {</span>
<span class="lineNum">     399 </span>            :   int status;
<span class="lineNum">     400 </span><span class="lineCov">          9 :   int n = lua_gettop(L);</span>
<span class="lineNum">     401 </span><span class="lineCov">          9 :   luaL_argcheck(L, n &gt;= 2, 2, &quot;value expected&quot;);</span>
<span class="lineNum">     402 </span><span class="lineCov">          8 :   lua_pushvalue(L, 1);  /* exchange function... */</span>
<span class="lineNum">     403 </span><span class="lineCov">          8 :   lua_copy(L, 2, 1);  /* ...and error handler */</span>
<span class="lineNum">     404 </span><span class="lineCov">          8 :   lua_replace(L, 2);</span>
<span class="lineNum">     405 </span><span class="lineCov">          8 :   status = lua_pcallk(L, n - 2, LUA_MULTRET, 1, 0, pcallcont);</span>
<span class="lineNum">     406 </span><span class="lineCov">          7 :   return finishpcall(L, (status == LUA_OK));</span>
<span class="lineNum">     407 </span>            : }
<span class="lineNum">     408 </span>            : 
<span class="lineNum">     409 </span>            : 
<span class="lineNum">     410 </span><span class="lineCov">       4206 : static int luaB_tostring (lua_State *L) {</span>
<span class="lineNum">     411 </span><span class="lineCov">       4206 :   luaL_checkany(L, 1);</span>
<span class="lineNum">     412 </span><span class="lineCov">       4205 :   luaL_tolstring(L, 1, NULL);</span>
<span class="lineNum">     413 </span><span class="lineCov">       4204 :   return 1;</span>
<span class="lineNum">     414 </span>            : }
<span class="lineNum">     415 </span>            : 
<span class="lineNum">     416 </span>            : 
<span class="lineNum">     417 </span>            : static const luaL_Reg base_funcs[] = {
<span class="lineNum">     418 </span>            :   {&quot;assert&quot;, luaB_assert},
<span class="lineNum">     419 </span>            :   {&quot;collectgarbage&quot;, luaB_collectgarbage},
<span class="lineNum">     420 </span>            :   {&quot;dofile&quot;, luaB_dofile},
<span class="lineNum">     421 </span>            :   {&quot;error&quot;, luaB_error},
<span class="lineNum">     422 </span>            :   {&quot;getmetatable&quot;, luaB_getmetatable},
<span class="lineNum">     423 </span>            :   {&quot;ipairs&quot;, luaB_ipairs},
<span class="lineNum">     424 </span>            :   {&quot;loadfile&quot;, luaB_loadfile},
<span class="lineNum">     425 </span>            :   {&quot;load&quot;, luaB_load},
<span class="lineNum">     426 </span>            : #if defined(LUA_COMPAT_LOADSTRING)
<span class="lineNum">     427 </span>            :   {&quot;loadstring&quot;, luaB_load},
<span class="lineNum">     428 </span>            : #endif
<span class="lineNum">     429 </span>            :   {&quot;next&quot;, luaB_next},
<span class="lineNum">     430 </span>            :   {&quot;pairs&quot;, luaB_pairs},
<span class="lineNum">     431 </span>            :   {&quot;pcall&quot;, luaB_pcall},
<span class="lineNum">     432 </span>            :   {&quot;print&quot;, luaB_print},
<span class="lineNum">     433 </span>            :   {&quot;rawequal&quot;, luaB_rawequal},
<span class="lineNum">     434 </span>            :   {&quot;rawlen&quot;, luaB_rawlen},
<span class="lineNum">     435 </span>            :   {&quot;rawget&quot;, luaB_rawget},
<span class="lineNum">     436 </span>            :   {&quot;rawset&quot;, luaB_rawset},
<span class="lineNum">     437 </span>            :   {&quot;select&quot;, luaB_select},
<span class="lineNum">     438 </span>            :   {&quot;setmetatable&quot;, luaB_setmetatable},
<span class="lineNum">     439 </span>            :   {&quot;tonumber&quot;, luaB_tonumber},
<span class="lineNum">     440 </span>            :   {&quot;tostring&quot;, luaB_tostring},
<span class="lineNum">     441 </span>            :   {&quot;type&quot;, luaB_type},
<span class="lineNum">     442 </span>            :   {&quot;xpcall&quot;, luaB_xpcall},
<span class="lineNum">     443 </span>            :   {NULL, NULL}
<span class="lineNum">     444 </span>            : };
<span class="lineNum">     445 </span>            : 
<span class="lineNum">     446 </span>            : 
<span class="lineNum">     447 </span><span class="lineCov">         87 : LUAMOD_API int luaopen_base (lua_State *L) {</span>
<span class="lineNum">     448 </span>            :   /* set global _G */
<span class="lineNum">     449 </span><span class="lineCov">         87 :   lua_pushglobaltable(L);</span>
<span class="lineNum">     450 </span><span class="lineCov">         87 :   lua_pushglobaltable(L);</span>
<span class="lineNum">     451 </span><span class="lineCov">         87 :   lua_setfield(L, -2, &quot;_G&quot;);</span>
<span class="lineNum">     452 </span>            :   /* open lib into global table */
<span class="lineNum">     453 </span><span class="lineCov">         87 :   luaL_setfuncs(L, base_funcs, 0);</span>
<span class="lineNum">     454 </span><span class="lineCov">         87 :   lua_pushliteral(L, LUA_VERSION);</span>
<span class="lineNum">     455 </span><span class="lineCov">         87 :   lua_setfield(L, -2, &quot;_VERSION&quot;);  /* set global _VERSION */</span>
<span class="lineNum">     456 </span><span class="lineCov">         87 :   return 1;</span>
<span class="lineNum">     457 </span>            : }
<span class="lineNum">     458 </span>            : 
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.13</a></td></tr>
  </table>
  <br>

</body>
</html>
